<template>
  <div>
    <!-- 面包屑 -->
    <div class="crumbs">
      <el-breadcrumb separator-class="el-icon-arrow-right">
        <el-breadcrumb-item :to="{ path: '/' }"><i class="el-icon-s-fold"></i> 首页</el-breadcrumb-item>
        <el-breadcrumb-item>商户管理</el-breadcrumb-item>
        <el-breadcrumb-item>商户管理</el-breadcrumb-item>
      </el-breadcrumb>
    </div>
    <!-- 表单 -->
    <el-card shadow="always">
      <!-- 表头 -->
      <div slot="header">
        <el-form :inline="true" label-width="80px" class="demo-form-inline">
          <el-form-item label="商户名称:">
            <el-input v-model="merchants.name" placeholder="请输入商户名称" size="medium"></el-input>
          </el-form-item>
          <el-form-item label="门店地址:">
            <el-input v-model="merchants.address" placeholder="请输入门店地址" size="medium"></el-input>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" size="medium" @click="searchMerchant">查询</el-button>
            <el-button size="medium" @click="clearMerchant">取消</el-button>
          </el-form-item>
        </el-form>
      </div>
      <!-- 表体 -->
      <!-- 表格 -->
      <el-table v-loading="loading" border style="width: 100%" size="medium" :data="tableData">
        <el-table-column prop="name" label="商户名称">
        </el-table-column>
        <el-table-column prop="address" label="门店地址">
        </el-table-column>

        <el-table-column prop="director" label="负责人">
        </el-table-column>
        <el-table-column prop="checktime" label="注册时间">
        </el-table-column>
        <el-table-column prop="state" label="审核状态">
          <template slot-scope="scope">
            <el-tag v-if="scope.row.state === 1" type="success">已通过</el-tag>
            <el-tag v-else-if="scope.row.state === 0" type="danger">已拒绝</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="address" label="操作" fixed="right" min-width="140">
          <template slot-scope="scope">
            <el-button size="mini" type="primary" icon="el-icon-edit" @click="goToDetail(scope.row)">详情</el-button>
          </template>
        </el-table-column>
      </el-table>

      <!-- 分页 -->
      <el-pagination style="text-align: center;margin-top: 20px;" :current-page.sync="pageInfo.pageNum"
        :page-sizes="[3, 5, 10, 20]" :page-size.sync="pageInfo.pageSize" layout="prev, pager, next,total,jumper,->, sizes"
        :total="pageInfo.total" @current-change="getMerchant" @size-change="getMerchant">
      </el-pagination>

    </el-card>



  </div>
</template>

<script>


export default {
  name: "MerchantManager",
  data() {
    return {
      pageInfo: {
        pageNum: 1,
        pageSize: 3,
        total: 20,

      },
      merchants: {
        address: '',
        name: '',
        id: 0
      },
      tableData: [],
      loading: false,

    }
  },
  mounted() {
    this.getMerchant();
  },
  methods: {
    async getMerchant() {
      this.loading = true;
      let { pageNum, pageSize } = this.pageInfo;
      let { id, name, address } = this.merchants
      let res = await this.$API.Merchant.reqMerchant(name, address, pageNum, pageSize, id)
      if (res.code == 200) {
        this.pageInfo.total = res.data.total;
        this.tableData = res.data.list
      } else {
        this.tableData = [];
        this.pageInfo.total = 0;
        this.$message({ message: '没有数据', type: 'error' })
      }
      this.loading = false;
    },
    async searchMerchant() {
      await this.getMerchant();
    },
    clearMerchant() {
      this.merchants = {
        address: '',
        name: '',
        id: 0
      };
      this.pageInfo.pageNum = 1;
      this.getMerchant();
    },
    goToDetail(row) {
      this.$router.push({ name: 'MerchantDetail', query: { id: row.id } }) // 传递参数，如需要可以修改params的内容
    }
  },

}
</script>

<style scoped></style>